this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};this.BX.Landing.UI=this.BX.Landing.UI||{};(function(e,t,i,n,a,s,o,l,r,d,u){"use strict";var c=function(e){babelHelpers.inherits(c,e);function c(e){var i;babelHelpers.classCallCheck(this,c);i=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(c).call(this,e));i.dimensions=babelHelpers["typeof"](e.dimensions)==="object"?e.dimensions:null;i.create2xByDefault=e.create2xByDefault!==false;i.uploadParams=babelHelpers["typeof"](e.uploadParams)==="object"?e.uploadParams:{};i.onValueChangeHandler=e.onValueChange?e.onValueChange:function(){};i.type=i.content.type||"image";i.contextType=e.contextType||c.CONTEXT_TYPE_CONTENT;i.allowClear=e.allowClear;i.input.innerText=i.content.src;i.input.hidden=true;i.input2x=i.createInput();i.input2x.innerText=i.content.src2x||"";i.input2x.hidden=true;i.layout.classList.add("landing-ui-field-image");i.compactMode=e.compactMode===true;if(i.compactMode){i.layout.classList.add("landing-ui-field-image--compact")}i.disableAltField=typeof e.disableAltField==="boolean"?e.disableAltField:false;i.fileInput=c.createFileInput(i.selector);i.fileInput.addEventListener("change",i.onFileInputChange.bind(babelHelpers.assertThisInitialized(i)));i.linkInput=c.createLinkInput();i.linkInput.onInputHandler=t.Runtime.debounce(i.onLinkInput.bind(babelHelpers.assertThisInitialized(i)),777);i.dropzone=c.createDropzone(i.selector);i.dropzone.hidden=true;i.onDragOver=i.onDragOver.bind(babelHelpers.assertThisInitialized(i));i.onDragLeave=i.onDragLeave.bind(babelHelpers.assertThisInitialized(i));i.onDrop=i.onDrop.bind(babelHelpers.assertThisInitialized(i));i.dropzone.addEventListener("dragover",i.onDragOver);i.dropzone.addEventListener("dragleave",i.onDragLeave);i.dropzone.addEventListener("drop",i.onDrop);i.clearButton=c.createClearButton();i.clearButton.on("click",i.onClearClick.bind(babelHelpers.assertThisInitialized(i)));i.preview=c.createImagePreview();i.preview.appendChild(i.clearButton.layout);i.preview.style.backgroundImage="url("+i.input.innerText.trim()+")";i.onImageDragEnter=i.onImageDragEnter.bind(babelHelpers.assertThisInitialized(i));i.preview.addEventListener("dragenter",i.onImageDragEnter);i.loader=new BX.Loader({target:i.preview});i.icon=c.createIcon();i.image=c.createImageLayout();i.image.appendChild(i.preview);i.image.appendChild(i.icon);i.image.dataset.fileid=i.content.id;i.image.dataset.fileid2x=i.content.id2x;i.hiddenImage=t.Dom.create("img",{props:{className:"landing-ui-field-image-hidden"}});if(t.Type.isPlainObject(i.content)&&"src"in i.content){i.hiddenImage.src=i.content.src}i.altField=c.createAltField();i.altField.setValue(i.content.alt);i.left=c.createLeftLayout();i.left.appendChild(i.dropzone);i.left.appendChild(i.image);i.left.appendChild(i.hiddenImage);if(i.description){i.left.appendChild(i.description)}i.left.appendChild(i.altField.layout);i.left.appendChild(i.linkInput.layout);i.aiButton=c.createAiButton(i.compactMode);i.aiButton.on("click",i.onAiClick.bind(babelHelpers.assertThisInitialized(i)));i.aiPicker=null;i.uploadButton=c.createUploadButton(i.compactMode);i.uploadButton.on("click",i.onUploadClick.bind(babelHelpers.assertThisInitialized(i)));i.editButton=c.createEditButton();i.editButton.on("click",i.onEditClick.bind(babelHelpers.assertThisInitialized(i)));i.right=c.createRightLayout();if(d.Env.getInstance().getOptions()["allow_ai_image"]&&(i.type==="background"||i.type==="image")){i.right.appendChild(i.aiButton.layout)}i.right.appendChild(i.uploadButton.layout);i.right.appendChild(i.editButton.layout);i.form=c.createForm();i.form.appendChild(i.left);i.form.appendChild(i.right);i.layout.appendChild(i.form);i.enableTextOnly();if(!i.input.innerText.trim()||i.input.innerText.trim()===window.location.toString()){i.showDropzone()}if(i.disableAltField){i.altField.layout.hidden=true;i.altField.layout.style.display="none";i.altField.layout.classList.add("landing-ui-hide")}if(i.content.type==="icon"){i.type="icon";i.classList=i.content.classList;i.showPreview();i.altField.layout.hidden=true;t.Dom.addClass(i.layout,"landing-ui-field-image-icon")}i.makeAsLinkWrapper=t.Dom.create("div",{props:{className:"landing-ui-field-image-make-as-link-wrapper"},children:[t.Dom.create("div",{props:{className:"landing-ui-field-image-make-as-link-button"},children:[]})]});i.url=new BX.Landing.UI.Field.Link({content:i.content.url||{text:"",href:""},options:{siteId:n.Main.getInstance().options.site_id,landingId:n.Main.getInstance().id},contentRoot:i.contentRoot});i.isDisabledUrl=i.content.url&&i.content.url.enabled===false;if(i.isDisabledUrl){i.content.url.href=""}i.url.left.hidden=true;i.makeAsLinkWrapper.appendChild(i.url.layout);if(!e.disableLink){i.layout.appendChild(i.makeAsLinkWrapper)}i.content=i.getValue();BX.DOM.write(function(){this.adjustPreviewBackgroundSize()}.bind(babelHelpers.assertThisInitialized(i)));if(i.getValue().type==="background"||i.allowClear){i.clearButton.layout.classList.add("landing-ui-show")}i.uploader=new s.ImageUploader({uploadParams:i.uploadParams,additionalParams:{context:"imageeditor"},dimensions:i.dimensions,sizes:["1x","2x"],allowSvg:n.Main.getInstance().options.allow_svg===true});i.adjustEditButtonState();return i}babelHelpers.createClass(c,[{key:"onInputInput",value:function e(){this.preview.src=this.input.innerText.trim()}},{key:"onImageDragEnter",value:function e(t){t.preventDefault();t.stopPropagation();if(!this.imageHidden){this.showDropzone();this.imageHidden=true}}},{key:"onDragOver",value:function e(t){t.preventDefault();t.stopPropagation();this.dropzone.classList.add("landing-ui-active")}},{key:"onDragLeave",value:function e(t){t.preventDefault();t.stopPropagation();this.dropzone.classList.remove("landing-ui-active");if(this.imageHidden){this.imageHidden=false;this.showPreview()}}},{key:"onDrop",value:function e(t){t.preventDefault();t.stopPropagation();this.dropzone.classList.remove("landing-ui-active");this.onFileChange(t.dataTransfer.files[0]);this.imageHidden=false}},{key:"onFileChange",value:function e(t){this.showLoader();this.upload(t).then(this.setValue.bind(this)).then(this.hideLoader.bind(this))["catch"](function(e){console.error(e);this.hideLoader()}.bind(this))}},{key:"onFileInputChange",value:function e(t){this.onFileChange(t.currentTarget.files[0])}},{key:"onAiClick",value:function e(){this.getAiPicker().image()}},{key:"getAiPicker",value:function e(){var t=this;if(!this.aiPicker){var i=this.contextType===c.CONTEXT_TYPE_CONTENT?"large, heart shaped bouquet of red roses on a white background":"background, smooth, blue color";this.aiPicker=new u.Picker({startMessage:i,moduleId:"landing",contextId:this.getAiContext(),analyticLabel:"landing_image",history:true,popupContainer:r.PageObject.getRootWindow().document.body,onSelect:function e(i){var n=BX.util.add_url_param("/bitrix/tools/landing/proxy.php",{sessid:BX.bitrix_sessid(),url:i});BX.Landing.Utils.urlToBlob(n).then((function(e){e.lastModifiedDate=new Date;e.name=i.slice(i.lastIndexOf("/")+1);return e})).then(t.upload.bind(t)).then(t.setValue.bind(t)).then(t.hideLoader.bind(t))},onTariffRestriction:function e(){BX.UI.InfoHelper.show("limit_sites_ImageAssistant_AI")}});this.aiPicker.setLangSpace("image")}return this.aiPicker}},{key:"getAiContext",value:function e(){return"image_site_"+d.Env.getInstance().getSiteId()}},{key:"onUploadClick",value:function e(t){this.bindElement=t.currentTarget;t.preventDefault();if(!this.uploadMenu){this.uploadMenu=BX.Main.MenuManager.create({id:"upload_"+this.selector+ +new Date,bindElement:this.bindElement,bindOptions:{forceBindPosition:true},items:[{text:i.Loc.getMessage("LANDING_IMAGE_UPLOAD_MENU_UNSPLASH"),onclick:this.onUnsplashShow.bind(this)},{text:i.Loc.getMessage("LANDING_IMAGE_UPLOAD_MENU_GOOGLE"),onclick:this.onGoogleShow.bind(this)},{text:i.Loc.getMessage("LANDING_IMAGE_UPLOAD_MENU_UPLOAD"),onclick:this.onUploadShow.bind(this)},{text:i.Loc.getMessage("LANDING_IMAGE_UPLOAD_MENU_LINK"),onclick:this.onLinkShow.bind(this)}],events:{onPopupClose:function(){this.bindElement.classList.remove("landing-ui-active");if(this.uploadMenu){this.uploadMenu.destroy();this.uploadMenu=null}}.bind(this)},targetContainer:this.contentRoot});if(!this.contentRoot){this.bindElement.parentNode.appendChild(this.uploadMenu.popupWindow.popupContainer)}}this.bindElement.classList.add("landing-ui-active");this.uploadMenu.toggle();if(!this.contentRoot&&this.uploadMenu){var n=BX.pos(this.bindElement,this.bindElement.parentNode);this.uploadMenu.popupWindow.popupContainer.style.top=n.bottom+"px";this.uploadMenu.popupWindow.popupContainer.style.left="auto";this.uploadMenu.popupWindow.popupContainer.style.right="5px"}}},{key:"onUnsplashShow",value:function e(){this.uploadMenu.close();BX.Landing.UI.Panel.Image.getInstance().show("unsplash",this.dimensions,this.loader,this.uploadParams).then(this.upload.bind(this)).then(this.setValue.bind(this)).then(this.hideLoader.bind(this))["catch"](function(e){console.error(e);this.hideLoader()}.bind(this))}},{key:"onGoogleShow",value:function e(){this.uploadMenu.close();BX.Landing.UI.Panel.Image.getInstance().show("google",this.dimensions,this.loader,this.uploadParams).then(this.upload.bind(this)).then(this.setValue.bind(this)).then(this.hideLoader.bind(this))["catch"](function(e){BX.Landing.ErrorManager.getInstance().add({type:"error",action:"BAD_IMAGE",hideSupportLink:true});console.error(e);this.hideLoader()}.bind(this))}},{key:"onUploadShow",value:function e(){this.uploadMenu.close();this.fileInput.click()}},{key:"onLinkShow",value:function e(){this.uploadMenu.close();this.showLinkField();this.linkInput.setValue("")}},{key:"onEditClick",value:function e(t){t.preventDefault();this.edit({src:this.hiddenImage.src})}},{key:"onClearClick",value:function e(t){t.preventDefault();this.setValue({src:""});this.fileInput.value="";this.showDropzone()}},{key:"showDropzone",value:function e(){this.dropzone.hidden=false;this.image.hidden=true;this.altField.layout.hidden=true;this.linkInput.layout.hidden=true}},{key:"showPreview",value:function e(){this.dropzone.hidden=true;this.image.hidden=false;this.altField.layout.hidden=false;this.linkInput.layout.hidden=true}},{key:"showLinkField",value:function e(){this.dropzone.hidden=true;this.image.hidden=true;this.altField.layout.hidden=true;this.linkInput.layout.hidden=false}},{key:"onLinkInput",value:function e(i){var n=this;var a=t.Dom.create("img");a.src=i;a.onload=function(){n.showPreview();n.setValue({src:i,src2x:i})}}},{key:"showLoader",value:function e(){if(this.dropzone&&!this.dropzone.hidden){this.loader.show(this.dropzone);return}this.loader.show(this.preview)}},{key:"hideLoader",value:function e(){this.loader.hide()}},{key:"onInputClick",value:function e(t){t.preventDefault()}},{key:"isChanged",value:function e(){var i=BX.Landing.Utils.clone(this.content);var n=BX.Landing.Utils.clone(this.getValue());if(i.url&&t.Type.isString(i.url)){i.url=BX.Landing.Utils.decodeDataValue(i.url)}if(n.url&&t.Type.isString(n.url)){n.url=BX.Landing.Utils.decodeDataValue(n.url)}return JSON.stringify(i)!==JSON.stringify(n)}},{key:"adjustPreviewBackgroundSize",value:function e(){var i=t.Dom.create("img",{attrs:{src:this.getValue().src}});i.onload=function(){var e=this.preview.getBoundingClientRect();var t="cover";if(i.width>e.width||i.height>e.height){t="contain"}if(i.width<e.width&&i.height<e.height){t="auto"}BX.DOM.write(function(){this.preview.style.backgroundSize=t}.bind(this))}.bind(this)}},{key:"setValue",value:function e(t,i){if(t.type!=="icon"){if(!t||!t.src){this.input.innerText="";this.input2x.innerText="";this.preview.removeAttribute("style");this.input.dataset.ext="";this.showDropzone()}else{this.input.innerText=t.src;this.input2x.innerText=t.src2x||"";this.preview.style.backgroundImage='url("'+(t.src2x||t.src)+'")';this.preview.id=BX.util.getRandomString();this.hiddenImage.src=t.src2x||t.src;this.showPreview()}this.image.dataset.fileid=t&&t.id?t.id:-1;this.image.dataset.fileid2x=t&&t.id2x?t.id2x:-1;if(t.type==="image"){this.altField.layout.hidden=false;this.altField.setValue(t.alt)}this.classList=[]}else{this.preview.style.backgroundImage=null;this.classList=t.classList;this.icon.innerHTML='<span class="'+t.classList.join(" ")+'"></span>';this.showPreview();this.type="icon";this.altField.layout.hidden=true;this.altField.setValue("");this.input.innerText=""}if(t.url){this.url.setValue(t.url)}this.adjustPreviewBackgroundSize();this.adjustEditButtonState();this.hideLoader();this.onValueChangeHandler(this);BX.fireEvent(this.layout,"input");var n=new BX.Event.BaseEvent({data:{value:this.getValue()},compatData:[this.getValue()]});if(!i){this.emit("change",n)}}},{key:"adjustEditButtonState",value:function e(){var t=this.getValue();if(BX.Type.isStringFilled(t.src)){this.editButton.enable()}else{this.editButton.disable()}}},{key:"reset",value:function e(){this.setValue({type:this.getValue().type,id:-1,src:"",alt:""})}},{key:"getValue",value:function e(){var i={type:"",src:"",alt:"",url:""};var n=parseInt(this.image.dataset.fileid);if(t.Type.isNumber(n)&&n>0){i.id=n}var a=parseInt(this.image.dataset.fileid2x);if(t.Type.isNumber(a)&&a>0){i.id2x=a}var s=this.input2x.innerText.trim();if(t.Type.isString(s)&&s){i.src2x=s}if(this.type==="background"||this.type==="image"){i.src=this.input.innerText.trim()}if(this.type==="background"){i.type="background"}if(this.type==="image"){i.type="image";i.alt=this.altField.getValue()}if(this.type==="icon"){i.type="icon";i.classList=this.classList}i.url=Object.assign({},this.url.getValue(),{enabled:true});return i}},{key:"edit",value:function e(t){parent.BX.Landing.ImageEditor.edit({image:t.src,dimensions:this.dimensions}).then(function(e){return this.upload(e,{context:"imageEditor"})}.bind(this)).then(function(e){this.setValue(e)}.bind(this));var i=document.createElement("img");var n="/bitrix/images/landing/close.svg";n=BX.util.add_url_param(n,{action:"openImageEditor"});i.src=n+"?"+ +new Date}},{key:"upload",value:function e(i,n){if(i.type&&(i.type.includes("text")||i.type.includes("html"))){BX.Landing.ErrorManager.getInstance().add({type:"error",action:"BAD_IMAGE"});return Promise.reject({type:"error",action:"BAD_IMAGE"})}this.showLoader();var a=t.Type.isStringFilled(i.type)&&i.type.includes("png");var s=t.Type.isStringFilled(i.type)&&i.type.includes("svg");var o=new Promise(function(e){var t=a||s?["2x"]:["1x","2x"];if(this.create2xByDefault===false){var n=document.createElement("img");var o=URL.createObjectURL(i);var l=this.dimensions;n.onload=function(){URL.revokeObjectURL(o);if((this.width>=l.width||this.height>=l.height||this.width>=l.maxWidth||this.height>=l.maxHeight)===false){t=a||s?["2x"]:["1x"]}e(t)};n.src=o}else{e(t)}}.bind(this));return o.then(function(e){var t=function(){if(this.create2xByDefault===false&&BX.Type.isArrayFilled(e)){return e}return a||s?["2x"]:["1x","2x"]}.bind(this)();return this.uploader.setSizes(t).upload(i,n).then(function(e){this.hideLoader();if(t.length===1){return e[0]}return Object.assign({},e[0],{src2x:e[1].src,id2x:e[1].id})}.bind(this))}.bind(this))}}],[{key:"createFileInput",value:function e(i){return t.Dom.create("input",{props:{className:"landing-ui-field-image-dropzone-input"},attrs:{accept:"image/*",type:"file",id:"file_"+i,name:"picture"}})}},{key:"createLinkInput",value:function e(){var t=new a.TextField({id:"path_to_image",placeholder:i.Loc.getMessage("LANDING_IMAGE_UPLOAD_MENU_LINK_LABEL")});t.enableTextOnly();t.layout.hidden=true;return t}},{key:"createDropzone",value:function e(n){return t.Dom.create("label",{props:{className:"landing-ui-field-image-dropzone"},children:[t.Dom.create("div",{props:{className:"landing-ui-field-image-dropzone-text"},html:'<div class="landing-ui-field-image-dropzone-title">'+i.Loc.getMessage("LANDING_IMAGE_DROPZONE_TITLE")+"</div>"+'<div class="landing-ui-field-image-dropzone-subtitle">'+i.Loc.getMessage("LANDING_IMAGE_DROPZONE_SUBTITLE")+"</div>"})],attrs:{for:"file_"+n}})}},{key:"createClearButton",value:function e(){return new o.BaseButton("clear",{className:"landing-ui-field-image-action-button-clear"})}},{key:"createImagePreview",value:function e(){return t.Dom.create("div",{props:{className:"landing-ui-field-image-preview-inner"}})}},{key:"createIcon",value:function e(){return t.Dom.create("span",{props:{className:"landing-ui-field-image-preview-icon"}})}},{key:"createImageLayout",value:function e(){return t.Dom.create("div",{props:{className:"landing-ui-field-image-preview"}})}},{key:"createAltField",value:function e(){var t=new a.TextField({placeholder:i.Loc.getMessage("LANDING_FIELD_IMAGE_ALT_PLACEHOLDER"),className:"landing-ui-field-image-alt",textOnly:true});return t}},{key:"createLeftLayout",value:function e(){return t.Dom.create("div",{props:{className:"landing-ui-field-image-left"}})}},{key:"createAiButton",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;return new l.AiImageButton("ai",{text:i.Loc.getMessage("LANDING_FIELD_IMAGE_AI_BUTTON"+(t?"_COMPACT":"")),className:"landing-ui-field-image-ai-button"+(t?" --compact":"")})}},{key:"createUploadButton",value:function e(){return new o.BaseButton("upload",{text:i.Loc.getMessage("LANDING_FIELD_IMAGE_UPLOAD_BUTTON"),className:"landing-ui-field-image-action-button"})}},{key:"createEditButton",value:function e(){var t=new o.BaseButton("edit",{text:i.Loc.getMessage("LANDING_FIELD_IMAGE_EDIT_BUTTON"),className:"landing-ui-field-image-action-button"});return t}},{key:"createRightLayout",value:function e(){return t.Dom.create("div",{props:{className:"landing-ui-field-image-right"}})}},{key:"createForm",value:function e(){return t.Dom.create("form",{props:{className:"landing-ui-field-image-container"},attrs:{method:"post",enctype:"multipart/form-data"},events:{submit:function e(t){t.preventDefault()}}})}}]);return c}(a.TextField);babelHelpers.defineProperty(c,"CONTEXT_TYPE_CONTENT","content");babelHelpers.defineProperty(c,"CONTEXT_TYPE_STYLE","style");e.Image=c})(this.BX.Landing.UI.Field=this.BX.Landing.UI.Field||{},BX,BX.Landing,BX.Landing,BX.Landing.UI.Field,BX.Landing,BX.Landing.UI.Button,BX.Landing.UI.Button,BX.Landing,BX.Landing,BX.AI);
//# sourceMappingURL=image.bundle.map.js